using System;
using System.Collections.Generic;
using System.Text;
using Sedna.Core.Controller;

namespace Sedna.Core.Controls.Actions
{
    class CopyValueActionWithReplaceNewLine : CopyValueAction
    {
        protected string newLineSymbol = "\\n";

        public string NewLineSymbol
        {
            set { newLineSymbol = value; }
        }

        public override IActionResult Execute(IExecutionContext executionContext)
        {
            if (!String.IsNullOrEmpty(to))
            {
                if (!String.IsNullOrEmpty(from))
                {
                    value = valueParser == null ? executionContext.GetPropertyValue(from) : valueParser.Translate(null, executionContext.GetPropertyValue(from));
                    if(value is String)
                    {
                        value = ((String)value).Replace(newLineSymbol, Environment.NewLine);
                    }
                    executionContext.SetPropertyValue(to, value);
                }
                else
                    executionContext.SetPropertyValue(to, valueParser == null ? value : valueParser.Translate(null, value));
            }

            return CreateResult();
        }
 
    }
}
